package com.sfh.cp.mass;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.cp.R;
import com.sfh.cp.base.RefreshRecyleFragment;
import com.sfh.cp.mass.adapter.MassAdapter;
import com.sfh.cp.mass.pst.IPstMass;
import com.sfh.cp.widget.WidgetBaseToolbar;
import com.sfh.lib.mvp.IPresenter;
import com.sfh.lib.mvp.service.LoaderService;

import java.util.ServiceLoader;

import butterknife.BindView;
import crm.sfh.server.entity.EMass;
import crm.sfh.server.entity.req.ReqPage;
import crm.sfh.server.entity.rsp.TPage;

/**
 * 社团
 */

public class MassFragment extends RefreshRecyleFragment implements IPstMass.IVMass {

    IPstMass pstMass;
    @BindView(R.id.toolbar)
    WidgetBaseToolbar toolbar;
    @Nullable
    @Override
    public IPresenter getPresenter() {
        if (pstMass == null){
            pstMass = LoaderService.getService(IPstMass.class);
        }
        return pstMass;
    }

    @Override
    public void initData(View view) {
        super.initData(view);
        toolbar.setTitle("社团");
    }

    @Override
    public BaseQuickAdapter createAdapter() {
        return new MassAdapter();
    }

    @Override
    public boolean loadMore() {
        return false;
    }

    @Override
    public int getLayout() {
        return R.layout.mass_fragment;
    }
    @Override
    public void onRefreshUI() {
        if (pstMass == null){
            return;
        }
        this.nowPage = 1;
        ReqPage page = new ReqPage(nowPage);
        this.pstMass.listPageMass(page);
    }

    @Override
    public void onSuccess(TPage<EMass> data) {
        this.success(data);
    }

    @Override
    public void onError(String code, String error) {

        this.error(code,error);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        super.onItemClick(adapter, view, position);
        EMass mass = (EMass) adapter.getItem(position);
        MassActivity.startUI(getContext(),mass);
    }


}
